<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />
		<style>
			.mui-input-row label {
				font-family: 'Helvetica Neue', Helvetica, sans-serif;
				line-height: 1.1;
				float: left;
				width: 35%;
				padding: 11px 5px;
				font-size: 14px;
				color: #666;
			}
			
			.mui-btn {
				border: 1px solid #25CDDA;
				width: 300px;
				background-color: #25CDDA;
			}
			
			.mui-btn:active {
				border: 1px solid #58dde8!important;
				background-color: #58dde8!important;
			}
			
			.mui-bar-nav {
				background: #27CDDB;
			}
			
			.mui-action-back,
			.mui-title,
			.mui-action-back:active {
				color: #FFFFFF;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title" id="title">支付密码修改</h1>
		</header>
		<div class="mui-content">
			<div id="oldpass_div" class="mui-input-row" style="background: white;margin-top: 5px;margin-left: 5px;margin-right: 5px;">
				<label>旧密码：</label>
				<input id="passwordOld" type="password" class="mui-input-clear" placeholder="请输入旧支付密码" maxlength="20">
			</div>
			<div class="mui-input-row" style="background: white;margin-top: 5px;margin-left: 5px;margin-right: 5px;">
				<label>新密码：</label>
				<input id="new1" type="password" class="mui-input-clear" placeholder="请输入新支付密码" maxlength="20">
			</div>
			<div class="mui-input-row" style="background: white;margin-top: 5px;margin-left: 5px;margin-right: 5px;">
				<label>确认密码：</label>
				<input id="new2" type="password" class="mui-input-clear" placeholder="请再次输入新支付密码" maxlength="20">
			</div>

			<div class="mui-button-row" style="margin-bottom: 20px;margin-top: 10px;">
				<button type="button" class="mui-btn mui-btn-primary" id="confirm">确定修改</button>&nbsp;&nbsp;
			</div>
		</div>

		<script src="../js/mui.min.js "></script>
		<script type="text/javascript" src="../js/public.js"></script>
		<script type="text/javascript ">
			mui.init();
			var oldpassLi = document.getElementById('oldpass_div');

			var payword = "";
			var member = null;
			mui.plusReady(function() {
				swipeBack();

				member = JSON.parse(plus.storage.getItem("member"));
				if(member) {
					payword = member.payword;
				}
				if(!payword) {
					oldpassLi.style.display = "none";
				}
			})

			document.getElementById('confirm').addEventListener('tap', function() {
				var oldpass = "";
				if(payword) {
					var passwordOld = document.getElementById('passwordOld');
					oldpass = passwordOld.value;
					if(!oldpass) {
						mymui("请输入旧密码");
						return;
					}
				}

				var password1 = document.getElementById('new1');
				var password2 = document.getElementById('new2');
				var new1 = password1.value;
				var new2 = password2.value;

				//验证密码
				if(!new1) {
					mymui("请输入新密码");
					return;
				}
				if(new1.length < 6) {
					mymui("新密码至少6位");
					return;
				}
				//验证密码
				if(!new2) {
					mymui("请再次输入新密码");
					return;
				}

				if(new1 != new2) {
					mymui("两次输入的密码不符");
					return;
				}

				var mdata = "";
				if(payword) {
					mdata = {
						"payword1": new1,
						"payword2": new2,
						"paywordOld": oldpass
					};
				} else {
					mdata = {
						"payword1": new1,
						"payword2": new2
					};
				}
				commitModifyPassword(mdata);
			});

			//修改密码
			function commitModifyPassword(mdata) {
				mui.postJSON(ModifyUserInfo, mdata, function(data) {
					mConsole.log("修改交易密码:" + JSON.stringify(data));
					var code = data.code;
					if(code == 0) {
						// 显示自动消失的提示消息
						mymui("交易密码设置成功");
						member.payword = "set";
						plus.storage.setItem("member", JSON.stringify(member));
						openSetting();
					} else {
						mymui(data.msg);
					}
				});
			}

			function openSetting() {
				//触发详情页面的setUserState事件
				mui.fire(plus.webview.getWebviewById('setting'), 'setUserState', {});
				//打开
				mui.back();
			}
		</script>
	</body>

</html>